home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / ScreenSavers / SpaceSaver / Source / BackView.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  2.0 KB  |  89 lines

  1. // BackView.m
  2. //
  3. // a View that provides some functionality that some screen savers might
  4. // find useful; you can subclass this class if you like.
  5. //
  6. // You may freely copy, distribute, and reuse the code in this example.
  7. // NeXT disclaims any warranty of any kind, expressed or implied, as
  8. // to its fitness for any particular use.
  9.  
  10. #import "BackView.h"
  11. #import <appkit/NXImage.h>
  12. #import <dpsclient/wraps.h>
  13. #import <libc.h>
  14.  
  15. @implementation BackView
  16.  
  17. - initFrame:(const NXRect *) frameRect
  18. {
  19.     [super initFrame:frameRect];
  20.  
  21.     return [[self allocateGState] setImageConstraints];
  22. }
  23.  
  24. - sizeTo:(NXCoord) width :(NXCoord) height
  25. {
  26.     [super sizeTo:width :height];
  27.  
  28.     return [self setImageConstraints];
  29. }
  30.  
  31. - drawSelf:(const NXRect *) rects :(int) rectCount
  32. {
  33.     if (rects == NULL || rectCount == 0) return self;
  34.  
  35.     PSsetgray(NX_BLACK);
  36.     NXRectFill(rects);
  37.  
  38.     return self;
  39. }
  40.  
  41. - setImageConstraints
  42. {
  43.     maxCoord.x = bounds.size.width - imageRect.size.width;
  44.     maxCoord.y = bounds.size.height - imageRect.size.height;
  45.  
  46.     if (maxCoord.x < 0) maxCoord.x = 0;
  47.     if (maxCoord.y < 0) maxCoord.y = 0;
  48.  
  49.     return self;
  50. }
  51.  
  52. - setImage: newImage
  53. {
  54.     [(image = newImage) getSize:&imageRect.size];
  55.  
  56.     return [[self setImageConstraints] display];
  57. }
  58.  
  59. - (BOOL) useBufferedWindow
  60. {
  61.     return YES; // by default; can be overridden in subclasses
  62. }
  63.  
  64. - (BOOL) timePassed:(BStimeval) delay
  65. {
  66.     BOOL result = NO;
  67.     BStimeval msec, now = currentTimeInMs();
  68.  
  69.     if (BVthen == 0) BVthen = now; // added by shou-h@nexus.or.jp
  70.     msec = now - BVthen;
  71.  
  72.     // so as not to suck too many cycles, if I'm waiting for some
  73.     // time more than a tenth of a second in the future, I sleep
  74.     // a while.  This interval is short enough that the app shouldn't
  75.     // seem unresponsive to user actions.
  76.  
  77.     // ok, so you'd never pull this trick if the user had to type.
  78.     // A better solution would be to coordinate the timed entry better,
  79.     // but I get slightly better performance from spinning in my
  80.     // timed entry (a bad idea for most apps...)
  81.  
  82.     if ((msec + 120) < delay) usleep(110000);
  83.     else if (result = (msec > delay)) BVthen = now;
  84.  
  85.     return result;
  86. }
  87.  
  88. @end
  89.